﻿using System;
using System.ComponentModel;
using NUnit.Framework;
/*
namespace MockFramework.Tests
{
    [TestFixture]
    public class MockedEventsFixture
    {
        [Test]
        public void ShouldExpectAddHandler()
        {
            var view = new Mock<IFooView>();

            var presenter = new FooPresenter(view.Object);
            bool fired = false;

            presenter.Fired += (sender, args) =>
            {
                fired = true;
                Assert.True(args is FooArgs);
                Assert.AreEqual("foo", ((FooArgs)args).Value);
            };

            view.Raise(v => v.FooSelected += null, new FooArgs { Value = "foo" });

            Assert.True(fired);
        }

        [Test]
        public void ShouldRaiseEventIfAttachedAfterUse()
        {
            var view = new Mock<IFooView>();
            var presenter = new FooPresenter(view.Object);

            Assert.False(presenter.Canceled);

            view.Raise(v => v.Canceled += null, EventArgs.Empty);

            Assert.True(presenter.Canceled);
        }

        [Test]
        public void ShouldNotThrowIfEventIsNotMocked()
        {
            var view = new Mock<IFooView>();

            // Presenter class attaches to the event and nothing happens.
            var presenter = new FooPresenter(view.Object);
        }

        [Test]
        public void ShouldRaiseEventWhenExpectationMet()
        {
            var mock = new Mock<IAdder<string>>();

            var raised = false;
            mock.Setup(add => add.Add("foo"))
                .Raises(m => m.Added += null, EventArgs.Empty);

            mock.Object.Added += (s, e) => raised = true;

            mock.Object.Add("foo");

            Assert.True(raised);
        }
        
        [Test]
        public void ShouldRaiseEventWithFunc()
        {
            var mock = new Mock<IAdder<string>>();

            var raised = false;
            mock.Setup(add => add.Add("foo"))
                .Raises(m => m.Added += null, () => EventArgs.Empty);

            mock.Object.Added += (s, e) => raised = true;
            mock.Object.Add("foo");

            Assert.True(raised);
        }

     
     
        [Test]
        public void ShouldAttachAndDetachListener()
        {
            var parent = new Mock<IParent>();
            var raised = false;
            EventHandler<EventArgs> listener = (sender, args) => raised = true;

            parent.Object.Event += listener;

            parent.Raise(p => p.Event += null, EventArgs.Empty);

            Assert.True(raised);

            raised = false;

            parent.Object.Event -= listener;

            parent.Raise(p => p.Event += null, EventArgs.Empty);

            Assert.False(raised);
        }

        bool raisedField = false;

        [Test]
        public void ShouldAttachAndDetachListenerMethod()
        {
            var parent = new Mock<IParent>();
            raisedField = false;

            parent.Object.Event += this.OnRaised;

            parent.Raise(p => p.Event += null, EventArgs.Empty);

            Assert.True(raisedField);

            raisedField = false;

            parent.Object.Event -= OnRaised;

            parent.Raise(p => p.Event += null, EventArgs.Empty);

            Assert.False(raisedField);
        }

        [Test]
        public void ShouldAllowListenerListToBeModifiedDuringEventHandling()
        {
            var parent = new Mock<IParent>();

            parent.Object.Event += delegate
            {
                parent.Object.Event += delegate { raisedField = true; };
            };

            parent.Raise(p => p.Event += null, EventArgs.Empty);

            // we don't expect the inner event to be raised the first time
            Assert.False(raisedField);

            // the second time around, the event handler added the first time
            // should kick in
            parent.Raise(p => p.Event += null, EventArgs.Empty);

            Assert.True(raisedField);
        }

        [Test]
        public void RaisesEvent()
        {
            var mock = new Mock<IAdder<string>>();

            bool raised = false;
            mock.Object.Added += (sender, args) => raised = true;

            mock.Raise(a => a.Added -= null, EventArgs.Empty);

            Assert.True(raised);
        }


        private void OnRaised(object sender, EventArgs e)
        {
            raisedField = true;
        }

        public class DoneArgs : EventArgs
        {
            public string Value { get; set; }
        }

        public interface IAdder<T>
        {
            event EventHandler<DoneArgs> Done;
            event EventHandler Added;
            void Add(T value);
            int Insert(T value, int index);
        }

        public class FooPresenter
        {
            public event EventHandler Fired;

            public FooPresenter(IFooView view)
            {
                view.FooSelected += (s, e) => Fired(s, e);
                view.Canceled += (s, e) => Canceled = true;
            }

            public bool Canceled { get; set; }
        }

        public class FooArgs : EventArgs
        {
            public object Value { get; set; }
            public object[] Args { get; set; }
        }

        public interface IFooView
        {
            event EventHandler<FooArgs> FooSelected;
            event EventHandler Canceled;
        }

        public interface IParent 
        {
            event EventHandler<EventArgs> Event;
            IAdder<int> Adder { get; set; }
        }

   }
}
*/